package net.wanho.controller;


import lombok.RequiredArgsConstructor;
import net.wanho.dto.LoginDTO;
import net.wanho.service.CaptchaService;
import net.wanho.service.UserInfoService;
import net.wanho.vo.AjaxResult;
import net.wanho.vo.CaptchaVo;
import net.wanho.vo.UserVo;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
//@Api(tags = "01.登录接口")
public class LoginController {

    private final CaptchaService captchaService;

    private final UserInfoService userInfoService;

    //@ApiOperation(value = "获取验证码")
    @GetMapping("/captchaImage")
    public AjaxResult captchaImage() {
        CaptchaVo captchaVo = captchaService.captcha();
        return AjaxResult.success(captchaVo);
    }

    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginDTO loginDTO) {
        String token = captchaService.login(loginDTO);
        return AjaxResult.success("登录成功",token);
    }

    @GetMapping("/curr-user")
    public AjaxResult currUser() {
        UserVo userVo = userInfoService.find();
        return AjaxResult.success(userVo);
    }

    @DeleteMapping("/logout")
    public AjaxResult logout() {
        return AjaxResult.success();
    }
}
